package com.metalrain.alm.service;

import com.metalrain.alm.enums.Modes;
import com.philips.lighting.model.PHBridge;
import com.philips.lighting.model.PHLight;
import com.philips.lighting.model.PHLightState;

import java.util.HashMap;

/**
* Created by administrator on 2014-06-12.
*/
public class LightRunnable implements Runnable {
    private final PHBridge bridge;
    private LightManager.LightTask lightTask;
    private final PHLight light;

    Modes currentMode = Modes.candle;
    private LightRunnable(PHBridge bridge, PHLight light) {
        this.bridge = bridge;
        this.light = light;
    }

    @Override
    public void run() {
        currentMode.process(light,bridge);
    }

    PHLightState lightState = new PHLightState();


    private static final HashMap<String, LightRunnable> Runnables = new HashMap();
    public static Runnable get(PHBridge bridge, PHLight light) {

        if (Runnables.containsKey(light.getIdentifier())) {
            return Runnables.get(light.getIdentifier());
        }

        LightRunnable r = new LightRunnable(bridge, light);
        Runnables.put(light.getIdentifier(), r);
        return r;
    }
}
